<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button>发送请求</button>
<button>取消请求</button>
</body>
<script src="./node_modules/axios/dist/axios.js"></script>
<script type="module">
    import axios from "./index.js";
    const btns = document.querySelectorAll("button");
    let cancelFn;
    btns[0].onclick = function () {
        if(cancelFn) cancelFn();
        axios({
            url: "http://zhangpeiyue.com/scoreList",
            params: {
                sex: "男"
            },
            cancelToken: new axios.CancelToken(fn => cancelFn = fn)
        }).then(value => {
            console.log(value);
        }).catch(err=>{
            console.log(err)
        })
    }
    btns[1].onclick = function () {
        if(cancelFn) cancelFn();
    }


</script>
</html>